<template>
  <el-dropdown trigger="click" v-if="authStore.authButtonList.admin">
    <div class="avatar">
      <img src="@/assets/images/avatar.gif" alt="avatar" />
    </div>
    <template #dropdown>
      <el-dropdown-menu>
        <el-dropdown-item @click="openDialog('uploadRef')">
          <el-icon><Edit /></el-icon>{{ $t("header.uploadFile") }}
        </el-dropdown-item>
        <el-dropdown-item @click="openDialog('changeRef')">
          <el-icon><Edit /></el-icon>{{ $t("header.changeFile") }}
        </el-dropdown-item>
      </el-dropdown-menu>
    </template>
  </el-dropdown>
  <div class="avatar" v-else>
    <img src="@/assets/images/avatar.gif" alt="avatar" />
  </div>
  <UploadFile ref="uploadRef"></UploadFile>
  <ChangeLink ref="changeRef"></ChangeLink>
</template>

<script setup lang="ts">
import { ref } from "vue";
import UploadFile from "./UploadFile.vue";
import ChangeLink from "./ChangeLink.vue";
import { useAuthStore } from "@/stores/modules/auth";

const authStore = useAuthStore();

// 打开修改密码和个人信息弹窗
const uploadRef = ref<InstanceType<typeof UploadFile> | null>(null);
const changeRef = ref<InstanceType<typeof ChangeLink> | null>(null);
const openDialog = (ref: string) => {
  if (ref == "uploadRef") uploadRef.value?.openDialog();
  if (ref == "changeRef") changeRef.value?.openDialog();
};
</script>

<style scoped lang="scss">
.avatar {
  width: 40px;
  height: 40px;
  overflow: hidden;
  cursor: pointer;
  border-radius: 50%;
  img {
    width: 100%;
    height: 100%;
  }
}
</style>
